package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.ProjectContact;
import com.kaishengit.util.db.DBHelp;
import com.kaishengit.util.db.RowMapper;

public class ProjectContactDao {
	private DBHelp<ProjectContact> db=new DBHelp<ProjectContact>();
	
	public void save(ProjectContact pc){
		
		String sql="insert into t_project_contact(id,projectId,contactId) values(?,?,?)";
		db.executeSQL(sql, pc.getId(),pc.getProjectId(),pc.getContactId());
	}
	public void  update(ProjectContact pc){
		
		String sql="update t_project_contact set projectId=?,contactId=? where id=?";
		db.executeSQL(sql, pc.getProjectId(),pc.getContactId(),pc.getId());	
	}
	
	public void del(ProjectContact pc){
		
		String sql="delete id,projectId,contactId form t_project_contact where id=?";
		db.executeSQL(sql, pc.getId());	
	}
	public List<ProjectContact> showAll(){
		
		String sql="select id,projectId,contactId form t_project_contact";
		return db.executeQueryToList(sql, new ProjectContactRowMapper());
	}
	
	
	private class ProjectContactRowMapper implements RowMapper<ProjectContact>{

		public ProjectContact mapRow(ResultSet rs) throws SQLException {
			
			ProjectContact pc=new ProjectContact();
			pc.setId(rs.getInt("id"));
			pc.setProjectId(rs.getInt("projectId"));
			pc.setContactId(rs.getInt("contactId"));
			
			return pc;
		}
	}
}
